package com.auto.survey.activity.geosurv

import android.content.Intent
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.auto.survey.MainActivity.Companion.KEY_MENU_IMAGE
import com.auto.survey.MainActivity.Companion.KEY_MENU_INTEN
import com.auto.survey.MainActivity.Companion.KEY_MENU_TITLE
import com.auto.survey.MainAdapter
import com.auto.survey.R
import com.auto.survey.activity.empty.EmptyActivity
import com.auto.survey.activity.geosurv.backward.BackWardActivity
import com.auto.survey.base.BaseActivity

/**
 * 展示各种测量原理的页面
 */
class GeoSurvActivity :BaseActivity() {

    override fun initView() {
        mTopBar?.visibility = View.VISIBLE
        mTopBar?.setBackgroundResource(R.color.action_bar)

        mComment_title?.visibility = View.VISIBLE
        mComment_title?.setBackgroundResource(R.color.action_bar)
        mComment_title?.setTitle("测量原理")


        val rvglid: RecyclerView = findViewById(R.id.id_RvGlidView)
        val rvlymanager: RecyclerView.LayoutManager = LinearLayoutManager(this@GeoSurvActivity)
        rvglid.layoutManager = rvlymanager
        val adapter = MainAdapter()
        adapter.setOnItemClickListener(object : MainAdapter.OnItemClickListener{
            override fun onItemClick(position: Int, map: Map<String, Any>) {
                try {
                    // 用户操作日志
                    val intent = Intent()
                    when (map[KEY_MENU_INTEN]) {
                        0x2111-> intent.setClass(this@GeoSurvActivity, EmptyActivity::class.java)
                        0x2112-> intent.setClass(this@GeoSurvActivity, BackWardActivity::class.java)
                        0x2113-> intent.setClass(this@GeoSurvActivity, EmptyActivity::class.java)
                        0x2114-> intent.setClass(this@GeoSurvActivity, EmptyActivity::class.java)
                        0x2115-> intent.setClass(this@GeoSurvActivity, EmptyActivity::class.java)
                        0x2116-> intent.setClass(this@GeoSurvActivity, EmptyActivity::class.java)
                    }
                    startActivity(intent)
                } catch (e:Exception) {
                    e.printStackTrace()
                }
            }
        })
        rvglid.adapter = adapter
        adapter.setDatas(menuData())
    }

    fun menuData(): MutableList<Map<String, Any>> {

        val datas: MutableList<Map<String, Any>> = ArrayList()

        val titls = arrayOf("极坐标法", "后方交会自由设站", "小角法", "方向偏移法", "全站仪自由设站法", "电子测距三角高程法")
        val imges = arrayOf(R.mipmap.login_bull_no_border, R.mipmap.login_bull_no_border, R.mipmap.login_bull_no_border,
            R.mipmap.login_bull_no_border, R.mipmap.login_bull_no_border, R.mipmap.login_bull_no_border)
        val targs = arrayOf(0x2111, 0x2112, 0x2113, 0x2114, 0x2115, 0x2116)

        for (i in titls.indices) {
            val menu1 = HashMap<String, Any>()
            menu1[KEY_MENU_TITLE] = titls[i]
            menu1[KEY_MENU_IMAGE] = imges[i]
            menu1[KEY_MENU_INTEN] = targs[i]

            datas.add(menu1)
        }


        return datas;
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_main
    }
}